/*******************************************************************************
 * Package: com.hngtrust.iir.report.service.impl
 * Type:    ReportLogBacServiceImpl
 * Date:    2021/9/14 11:27
 *
 * Copyright (c) 2021 HUANENG GUICHENG TRUST CORP.,LTD All Rights Reserved.
 *
 * You may not use this file except in compliance with the License.
 *******************************************************************************/
package com.hngtrust.iir.report.service.impl;

import com.hngtrust.framework.page.PageResult;
import com.hngtrust.framework.page.service.PageService;
import com.hngtrust.framework.security.util.SecurityUtils;
import com.hngtrust.iir.dto.ReqDTO;
import com.hngtrust.iir.report.controller.dto.ReportLogDTO;
import com.hngtrust.iir.report.controller.dto.ReportLogQueryVO;
import com.hngtrust.iir.report.entity.ReportLog;
import com.hngtrust.iir.report.service.ReportLogBacService;
import com.hngtrust.iir.report.service.ReportLogService;
import com.hngtrust.iir.user.entity.User;
import com.hngtrust.iir.util.ListUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 内部研报-研报操作日志
 *
 * @author Yujiaqi
 * @date 2021/9/14 11:27
 */
@Service
@Slf4j
public class ReportLogBacServiceImpl implements ReportLogBacService {
    
    @Autowired
    private PageService pageService;
    @Autowired
    private ReportLogService reportLogService;
    
    /**
     * 内部研报-研报操作日志列表
     * @param reqDTO
     * @return
     */
    @Override
    public PageResult<ReportLogDTO> listLog(ReqDTO<ReportLogQueryVO> reqDTO) {
        Date createTime = reqDTO.getContent().getCreateTime();
        ReportLog reportLog = new ReportLog();
        if(createTime != null) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
            String format1 = format.format(createTime);
            reportLog.setCreateTimeDt(format1);
        }
        
        //当前登录
        User loginUser = (User) SecurityUtils.getLoginUser().getAdditionalInfo();
        reportLog.setCreateUserId(loginUser.getId());
        
        PageResult<ReportLog> page = pageService.page(reqDTO.getPageParam(), () -> reportLogService.queryList(reportLog));
        
        PageResult<ReportLogDTO> pageResult = new PageResult<>();
        ListUtil<ReportLogDTO> listUtil = BeanUtils.instantiateClass(ListUtil.class);
        listUtil.copyList(page,pageResult, ReportLogDTO.class);
    
        return pageResult;
    }
}
